import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
    state: {
        name: 'tom',
        age: "22"
    },
    //getter 为 state 的计算属性
    getters: {
        getName: (state) => state.name,
        getAge: (state) => state.age
    },
    mutations: {
        setName: (state, data) => state.name = data,
        setAge: (state, data) => state.age = data
    },
    actions: {
        acSetName(context, name) {
            setTimeout(() => {
                context.commit('setName', name);
            }, 1000);
        }, acSetAge(context, age) {
            setTimeout(() => {
                context.commit('setAge', age);
            }, 1000);
        }
    }
})